#include "Srv_Service_Handler.h"
#include "../srv_asynch_man.h"
#include <iostream>
using namespace std;
Srv_Service_Handler::Srv_Service_Handler(int h,Srv_Asynch_Man  *pAsynch):m_pAsynch(pAsynch)
,m_client_socket(h)
{
    nub = 2;
}

Srv_Service_Handler::~Srv_Service_Handler( void )
{
    m_client_socket = 0;
}

void Srv_Service_Handler::Open()
{

}

void Srv_Service_Handler::close()
{

}

int Srv_Service_Handler::socket() const
{
	return m_client_socket;
}

Srv_Asynch_Man  * Srv_Service_Handler::Asynch_Acceptor() const
{
    return m_pAsynch;
}

bool Srv_Service_Handler::send(const char *pBuffr, int size)
{
    if(Asynch_Acceptor())
    {
        Asynch_Acceptor()->append_write_buf(socket(),pBuffr,size);
        return true;
    }

    return false;
}

void Srv_Service_Handler::destroy()
{
    if(Asynch_Acceptor() && ( socket() != 0))
         Asynch_Acceptor()->destroy_connection(socket());
}

void Srv_Service_Handler::send1(const char *pBuffr, int size)
{
   // of << ncom2<< " : " << ncom1<< " : " << size << endl;
}

void Srv_Service_Handler::handle_read_stream(const char *ptr,int len)
{
    nub += len;
    send(ptr,len) ;	//
}

 //bool Srv_Service_Handler::WriteRequest(const  char *pBuffr,int size)
 //{
//	return  Asynch_Acceptor()->WriteRequest(socket(),pBuffr,size);
 //}

